package com.ys.controller.api.sys;

import com.ys.entity.sys.TbCompanyInfo;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.TbCompanyInfoService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 公司信息管理
 */
@Controller
@RequestMapping("/api/inter/tbCompanyInfo")
public class ApiInterTbCompanyInfoController {
    private static final Logger logger = LoggerFactory.getLogger(ApiInterTbCompanyInfoController.class);

    @Autowired
    private CommonApiService<TbCompanyInfo> commonApiService;

    @Autowired
    private TbCompanyInfoService tbCompanyInfoService;

    @RequiresPermissions("tbCompanyInfo:view")
    @RequestMapping("/search")
    @ResponseBody
    public LayuiTableVoJA search(@ModelAttribute TbCompanyInfo cond){

        cond.setOrderby("A.createTime DESC");
        return commonApiService.searchLay(cond);
    }


    /**
     * 修改
     */
    @RequestMapping("/toEdit")
    @ResponseBody
    public R toEdit(HttpServletRequest request, @RequestParam Map<String, Object> params
    ) {
        try {
            logger.info("公司信息修改传参：" + params);
            //修改
            return tbCompanyInfoService.edit(params);
        } catch (Exception e) {
            logger.error("公司信息修改出错：", e.getMessage(), e);
            return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
        }
    }


    /**
     * 公司信息弹出框调用
     * @param cond
     * @return
     */
    @RequestMapping("/searchTk")
    @ResponseBody
    public LayuiTableVoJA searchTk(@ModelAttribute TbCompanyInfo cond){
        cond.setStatus(1);
        cond.setOrderby("A.createTime DESC");
        return commonApiService.searchLay(cond);
    }

    /**
     * 公司信息弹出框调用(预约采购)
     * @param cond
     * @return
     */
    @RequestMapping("/searchyycg")
    @ResponseBody
    public LayuiTableVoJA searchyycg(@ModelAttribute TbCompanyInfo cond){
        cond.setStatus(1);
        cond.setOrderby("A.createTime DESC")
                .setVid("C104");
        return commonApiService.searchLay(cond);
    }

}
